package com.bowen.chapter06.refactor.type;

import com.bowen.chapter06.refactor.Engineer;
import com.bowen.chapter06.refactor.Salesman;
import com.bowen.except.EmployeeTypeInValidException;

public class EmployeeType {

    /**
     * 员工类型
     */
    protected String type;

    public EmployeeType() {
    }

    /**
     * 重构第十一章 重构API 以工厂函数取代构造函数
     *
     * @param type
     * @return
     * @throws EmployeeTypeInValidException
     */
    public static EmployeeType createEmployeeType(String type) throws EmployeeTypeInValidException {
        if ("engineer".equals(type)) {
            return new EngineerType();
        } else if ("salesman".equals(type)) {
            return new SalesmanType();
        }
        throw new EmployeeTypeInValidException();
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}
